import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import ayncRouters from '@/router/dsyncRoutes'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    iscollapse: false,//是否折叠的变量
    token: "",
    userObj: {},//存储用户信息
    breadList: [],//面包屑导航数据
    routes: ayncRouters,//路由表
    chartCode: ""//存储图表的code
  },
  mutations: {
    changeCollapse (state) { //变量是否折叠变量
      state.iscollapse = !state.iscollapse
    },

    changeToken (state, token) { //改变token
      state.token = token;
    },
    changeUser (state, obj) {// 改变用户信息
      state.userObj = obj;
    },
    changeBread (state, list) { //改变面包屑导航数据
      state.breadList = list;
    },
    changeCode (state, code) { //改变图表的code
      state.chartCode = code;
    },
    setRoutes (state, routes) {
      state.routes = routes;
    }
  },
  actions: {
    acToken ({ commit }, token) { //改变token 的actions方法
      commit('changeToken', token)
    },
    actBread ({ commit }, list) {
      commit('changeBread', list)
    }
  },
  getters: {//控制折叠的getters
    iscollapse: state => state.iscollapse,
    token: state => state.token,
    userObj: state => state.userObj,
    breadList: state => state.breadList,
    chartCode: state => state.chartCode, //图表的code
    routes: state => state.routes
  },
  modules: {
  },
  plugins: [createPersistedState({ //配置持久化插件
    key: "jsoa"
  })]
})
